﻿#include "Frm01.h"

Frm01::Frm01(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm01::~Frm01() {
}

void Frm01::onInit(){
}

void Frm01::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Image : wMImage1                     -----------------------------*/
	wMImage1 = new STTImage(p_rt, this, "wMImage1");
	wMImage1->setMainArg(41, 76, 400, 400);
	wMImage1->addStateImg("0", "./images/b1g_400X400R0.png");

	/*----------------------------- Gauge : wMGauge1                     -----------------------------*/
	wMGauge1 = new STTMeter(p_rt, wMImage1, "wMGauge1");
	wMGauge1->setGaugeMainArg(0, 0, 400, 400, 80, 100, 200, 270, false, false, 1, 0, 0);
	wMGauge1->setGaugeMainStyle(9999, 0xffffff, 0xffffff, 0, 10, 2, 0x808080, 0, 0x0);
	wMGauge1->setGaugeNeedleStyle(0xff0000, 0, 20, "./images/zhizhen_181X20R0.png", 0, 0, 10, -9);
	wMGauge1->setGaugeFont(0x0, 16, "文泉驿微米黑", 0);
	wMGauge1->setGaugeTickStyle(0xff0000, 0xff, 0xff00ff, 0, 0, 12, 21);
	wMGauge1->setGaugeMajorTickStyle(0, 18, 0, 20);
	wMGauge1->setGaugeCircleStyle(9999, 0x0, 0xffffff, 0, 0, 0x0, 0, 0xffffff);
	wMGauge1->bindData(_V("变量_1"));

	/*----------------------------- Slider : wMSlider1                   -----------------------------*/
	wMSlider1 = new STTSlider(p_rt, this, "wMSlider1");
	wMSlider1->setMainArg(472, 173, 224, 22, 50, 100, 200, false);
	wMSlider1->setMainStyle(9999, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider1->setIndicStyle(9999, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, NULL);
	wMSlider1->setKnobStyle(7, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 7);
	wMSlider1->bindData(_V("变量_1"));
	wMSlider1->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm01::wMSlider1_vch_cb);

	/*----------------------------- Text : wMText1                       -----------------------------*/
	wMText1 = new STTTextArea(p_rt, this, "wMText1");
	wMText1->setMainArg(466, 36, 120, 35, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMText1->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 4, 4, 4, 4, 255);
	wMText1->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::UC);
	wMText1->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMText1->bindData(_V("变量_1"));

	/*----------------------------- Gauge : wMGauge2                     -----------------------------*/
	wMGauge2 = new STTMeter(p_rt, this, "wMGauge2");
	wMGauge2->setGaugeMainArg(476, 259, 302, 302, 80, 100, 200, 270, true, true, 1, 0, 30);
	wMGauge2->setGaugeMainStyle(9999, 0xffffff, 0xffffff, 0, 255, 2, 0x808080, 0, 0x0);
	wMGauge2->setGaugeNeedleStyle(0xff0000, 0, 6, NULL, 0, 3, 3, -9);
	wMGauge2->setGaugeFont(0x0, 16, "文泉驿微米黑", 0);
	wMGauge2->setGaugeTickStyle(0xff0000, 0xff, 0xff00ff, 5, 5, 12, 21);
	wMGauge2->setGaugeMajorTickStyle(7, 18, 6, 20);
	wMGauge2->setGaugeCircleStyle(9999, 0x0, 0xffffff, 0, 0, 0x0, 0, 0xffffff);
	wMGauge2->bindData(_V("变量_1"));

	/*called after widget created.*/

	return; //createParts END
}

void Frm01::onLoad(){
}

bool Frm01::onClosing(){
	return true;
}

void Frm01::onDispose(){
}

void Frm01::wMSlider1_vch_cb(uint16_t code, LvEvent e) {
	int a1 = wMGauge1->getStartAngle();
	int a2;
	vm->getInt("变量_1", a2);
	cout<<a1<<" - "<<a2<<endl;
	int vmin = 100;//这是仪表控件的最小值
	int vmax = 200;//这是仪表控件的最大值
	int angleRange = 270;//这是仪表控件的占用角度
	int angle = angleRange*(a2 - vmin)/(vmax-vmin);//计算当前值对应的角度
	STTMask::addAngle(wMImage1, 200, 200, a1, (a1+angle)%360);//蒙板，注意第2,3个参数是控件尺寸的1半
}
